/// @tags:
#include <algorithm>
#include <cstdio>
#include <iostream>

using std::__gcd;
using std::cin;
using std::cout;
using std::lower_bound;

namespace BlueQuantum {

typedef long long LL;

constexpr int N = 1e6 + 3, M = 2e3 + 3, mod = 1e9 + 7;

int n, q, P, fcnt;
int v[N], fact[M], ftot[M], f[2][M], g[M], sumtxp[N];

inline int inc(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}

inline void preowork() {
  sumtxp[1] = 2;
  for (int i = 2; i <= n; ++i) sumtxp[i] = sumtxp[i - 1] * 2 % mod;
  for (int i = 1; i <= n; ++i) --sumtxp[i] < 0 ? sumtxp[i] += mod : 0;
  for (int i = 1; i * i <= P; ++i)
    if (P % i == 0) {
      fact[++fcnt] = i;
      if (i * i != P) fact[++fcnt] = P / i;
    }
  std::sort(fact + 1, fact + fcnt + 1);
  for (int i = 1; i <= n; ++i) {
    ftot[lower_bound(fact + 1, fact + fcnt + 1, v[i]) - fact]++;
  }
  int cur = 0;
  for (int i = 1; i <= fcnt; ++i)
    if (ftot[i]) {
      cur ^= 1;
      for (int j = 1; j <= fcnt; ++j) f[cur][j] = f[cur ^ 1][j];
      for (int j = 1; j <= fcnt; ++j)
        if (f[cur ^ 1][j]) {
          int nxt = __gcd(fact[j], fact[i]);
          int pos = lower_bound(fact + 1, fact + fcnt + 1, nxt) - fact;
          f[cur][pos] = inc(f[cur][pos], (LL)f[cur ^ 1][j] * sumtxp[ftot[i]] % mod);
        }
      f[cur][i] = inc(f[cur][i], sumtxp[ftot[i]]);
    }
  for (int i = 1; i <= fcnt; ++i)
    for (int j = 1; j <= i; ++j)
      if (fact[i] % fact[j] == 0) g[i] = inc(g[i], f[cur][j]);
}

inline int main() {
  cin >> n >> q >> P;
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
    v[i] = __gcd(v[i], P);
  }
  preowork();
  for (int i = 1; i <= q; ++i) {
    int x;
    cin >> x;
    x = __gcd(x, P);
    cout << g[lower_bound(fact + 1, fact + fcnt + 1, x) - fact] << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4495 [HAOI2018] 奇怪的背包.in", "r", stdin);
  freopen("P4495 [HAOI2018] 奇怪的背包.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
